<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!-- struts的tag(標籤) 固定用法 -->
<%@ taglib uri="/struts-tags" prefix="s"%>

<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Generate Code</title>
		<script>
			function GeneratWrapperCode(){
				var errorMsg = "";
				
				if (document.generateCodeForm.packageName.value == "") {
					errorMsg += "請填寫所需產出物件之Package Name.\n";
				}
				
				if (document.generateCodeForm.tableName.selectedIndex == 0) {
					errorMsg += "請選擇所需產出之table.\n";
				}
				
				if (errorMsg == "") {
					document.generateCodeForm.action = "generateCode!generateWrapperCode.action";
					document.generateCodeForm.submit();
				} else {
					alert(errorMsg);
				}
			}
			
			function GeneratDAOCode(){
				var errorMsg = "";
				
				if (document.generateCodeForm.packageName.value == "") {
					errorMsg += "請填寫所需產出物件之Package Name.\n";
				}
				
				if (document.generateCodeForm.tableName.selectedIndex == 0) {
					errorMsg += "請選擇所需產出之table.\n";
				}
				
				if (errorMsg == "") {
					document.generateCodeForm.action = "generateCode!generateDAOCode.action";
					document.generateCodeForm.submit();
				} else {
					alert(errorMsg);
				}
			}
			
			function GeneratActionCode(){
				if (document.generateCodeForm.tableName.selectedIndex != 0) {
					document.generateCodeForm.action = "generateCode!generateActionCode.action";
					document.generateCodeForm.submit();
				} else {
					alert("請選擇所需產出之table.");
				}
			}
		</script>
	</head>
	<body>
		<fieldset>
			<legend> Generate Code </legend>
			<form name="generateCodeForm" id="generateCodeForm" action="post">
				<table width="100%" border="0">
					<tr>
						<td align="right" style="width: 45%">Package Name：</td>
						<td align="left" style="width: 55%">
							<input type="text" id="packageName" name="packageName" />
						</td>
					</tr>
					<tr>
						<td align="right">Table：</td>
						<td align="left">
							<s:set id="tableName" value="tableName"/>
							<select id="tableName" name="tableName">
								<option>請選擇</option>
								<s:iterator id="allTableList" value="allTableList">
									<option value="<s:property value="#allTableList.tableName"/>" <s:if test="#allTableList.tableName == #tableName">selected = "selected"</s:if>><s:property value="#allTableList.tableName"/></option>
								</s:iterator>
							</select>
						</td>
					</tr>
					<tr>
						<td colspan="2" align="center">
							<input type="button" value="Generat Wrapper Code" onclick="GeneratWrapperCode();"/>
							<input type="button" value="Generat DAO Code" onclick="GeneratDAOCode();"/>
							<input type="button" value="Generat Action Code" onclick="GeneratActionCode();"/>
							<input type="reset" value="重　設"/>
						</td>
					</tr>
				</table>
			</form>
		</fieldset>
		
		<s:if test="formatUpperTableName != null ">
			<s:iterator id="tableDataList" value="tableDataList">
				private String <s:property value="#tableDataList.getFormatLowerColumnName()" />;&nbsp;&nbsp;&nbsp;&nbsp;//<s:property value="#tableDataList.getComments()" /><br/>
			</s:iterator>
			<br/>
			
			<s:property value="formatUpperTableName" />DAO <s:property value="formatLowerTableName" />DAO = new <s:property value="formatUpperTableName" />DAO(con)<br/>
			<s:property value="formatUpperTableName" />Wrapper <s:property value="formatLowerTableName" />Wrapper = new <s:property value="formatUpperTableName" />Warpper()<br/>
			<s:iterator id="tableDataList" value="tableDataList">
				<s:property value="formatLowerTableName" />Wrapper.set<s:property value="#tableDataList.getFormatUpperColumnName()"/>(<s:property value="#tableDataList.getFormatLowerColumnName()"/>);<br/>
			</s:iterator>
			<br/>
			
			<s:set name="pkValue" value="" />
			<s:iterator id="pkList" value="pkList" status="cStatus">
				<s:if test="#cStatus.isFirst() == true">
					<s:if test="#cStatus.isLast() == false">
						<s:set name="pkValue" value="top+\", \"" />
					</s:if>
					<s:else>
						<s:set name="pkValue" value="#pkValue+top" />
					</s:else>
				</s:if>
				<s:else>
					<s:if test="#cStatus.isLast() == false">
						<s:set name="pkValue" value="#pkValue+top+\", \"" />
					</s:if>
					<s:else>
						<s:set name="pkValue" value="#pkValue+top" />
					</s:else>
				</s:else>
			</s:iterator>
			insert：<s:property value="formatLowerTableName" />DAO.insert(wra);<br/>
			<s:if test="pkList.size>0">			
				updateByPK：<s:property value="formatLowerTableName" />DAO.updateByPK(wra, <s:property value="#pkValue" />);<br/>
			</s:if>
			update：<s:property value="formatLowerTableName" />DAO.update(wra, "");<br/>
			<s:if test="pkList.size>0">			
				deleteByPK：<s:property value="formatLowerTableName" />DAO.deleteByPK(<s:property value="#pkValue" />);<br/>
			</s:if>
			delete：<s:property value="formatLowerTableName" />DAO.delete(wra, "");<br/>
			<s:if test="pkList.size>0">			
				queryByPK=<s:property value="formatLowerTableName" />DAO.queryByPK(<s:property value="#pkValue" />);<br/>
			</s:if>
			query：<s:property value="formatLowerTableName" />DAO.query(wra, "", "");<br/>
		</s:if>
		
	</body>
</html>